//
//  MaintabBarController.swift
//  weibo1
//
//  Created by 代亚洲 on 16/4/16.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class MainTableViewController: UITableViewController ,VisitorViewDelegate {
    
    // 用户是否登录
    var userLogon: Bool = AuthViewModel.sharedViewModel.islogin
    //    登录了展示tableview上
    // 可以在loadView里面判断是否登录，没有登录初始化访客视图并设置到 view 上
    override func loadView() {
                if userLogon {
                    super.loadView()
                }else{
                    // 没有登录
                    setupVisitorView()
                }
        
//        userLogon ? super.loadView() : setupVisitorView()
    }
    
    private func setupVisitorView(){
        view = visView
        
        // 设置左右两个item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didregisterclickbutton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didloginClickbutton")
        
    }
    //    didregisterclickbutton
    // MARK: - 实现协议里面的方法
    
    func didregisterclickbutton() {
        
        print("注册点击")
        
    }
    
    func didloginClickbutton() {
        
        print("登录点击")
        //        初始化
        let vc = AuthViewController()
        //        motai 出来登录界面
        self.presentViewController(UINavigationController(rootViewController: vc), animated: true, completion: nil )
    }
    
    
    
    // MARK: - 懒加载控件
    lazy var visView: VisitorView = {
        
        let view = VisitorView()
        view.delegate = self
        
        return view
        
    }()
    
}
